package com.springboot.web;

import com.springboot.model.User;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {

    @RequestMapping(value = "/user/detail")
    public ModelAndView userDetail(){
        ModelAndView mv = new ModelAndView();
        User user = new User();
        user.setId(1001);
        user.setAge(20);
        user.setUsername("sm");

        mv.setViewName("userDetail");
        mv.addObject("user",user);

        return mv;
    }

    @RequestMapping(value = "/url")
    public String urlExpression(Model model){
        model.addAttribute("id",1001);
        model.addAttribute("age",20);
        model.addAttribute("username","sunmiao");

        return "url";
    }

    @RequestMapping(value = "/test")
    public @ResponseBody String test(String username){
        return "请求路径/test,参数是："+username;
    }

    @RequestMapping(value = "/test1")
    public @ResponseBody String test1(Integer id,String username,Integer age){
        return "请求路径/test,参数id："+id+" username: "+username+" age: "+age;
    }
    
    @RequestMapping(value = "/test2/{id}")
    public @ResponseBody String test2(@PathVariable("id") Integer id){
        return "id="+id;
    }

    @RequestMapping(value = "/test3/{id}/{username}")
    public @ResponseBody String test2(@PathVariable("id") Integer id,
                                      @PathVariable("username") String username){
        return "id="+id+"------username="+username;
    }

    @RequestMapping(value = "/url2")
    public String url2(){
        return "url2";
    }

    @RequestMapping(value = "/property")
    public String property(){
        return "property";
    }
}
